//
//  UIBarButtonItem+Extension.swift
//  HLWeiBo
//
//  Created by jack on 15/12/5.
//  Copyright © 2015年 jack. All rights reserved.
//

import UIKit

//item 字体大小
let itemTitleFontSize: CGFloat = 14
//item 字体颜色
let itemTitleColor: UIColor = UIColor(white: 80/255, alpha: 1)

extension UIBarButtonItem {

    convenience init(imageName: String? = nil, title: String? = nil, target: AnyObject?, action: Selector) {
        self.init()
        
        let button = UIButton()
        
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if let img = imageName {
            //设置不同状态的图片
            button.setImage(UIImage(named: img), forState: .Normal)
            button.setImage(UIImage(named: "\(img)_highlighted"), forState: .Highlighted)
            
        }
        
        if let t = title {
            
            button.setTitle(t, forState: .Normal)
            button.setTitleColor(itemTitleColor, forState: .Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            button.titleLabel?.font = UIFont.systemFontOfSize(itemTitleFontSize)
        }
        
        button.sizeToFit()
        
        customView = button
        
    }
    
}












